package com.easy.demo.demos.web.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easy.demo.demos.web.mapper.LeaveMapper;
import com.easy.demo.demos.web.vo.Leave;
import com.easy.demo.demos.web.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author zhouchuang
 * @date 2024-11-12 23:02:55
 */
@Service
public class LeaveService {
    @Autowired
    private LeaveMapper leaveMapper;
    @Autowired
    private UserService userService;
//    private static Map<String,Leave> leaveMapperDb = new HashMap<String,Leave>();

    public Leave addLeave(Integer day , String reason){
        User user = userService.me();
        Leave leave = new Leave(user.getUsername(),day,reason,new Date());
        leaveMapper.insert(leave);
        return leave;
    }

    public List<Leave> leaves(){
        QueryWrapper queryWrapper = new QueryWrapper<>().eq("username",userService.me().getUsername());
        return leaveMapper.selectList(queryWrapper);
    }

    public Leave get(String id ){
       return leaveMapper.selectById(id);
    }

    public void update(Leave leave){
        leaveMapper.updateById(leave);
    }

}
